home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / crudetype / version3 / mytangle.ch < prev    next >
Text File  |  1990-12-05  |  13KB  |  414 lines

  1. TANGLE change file for Vax/VMS
  2. Copyright (C) 1983 by David Fuchs.  All rights are reserved.
  3.  
  4. MODIFICATION RECORD
  5. ~~~~~~~~~~~~~~~~~~~
  6. 21-NOV-1988    CNK <tex@cran.rmcs>
  7.     Set |last_text_char| = 255 (from 127).
  8.     See TeXhax vol. 88, no. 100
  9. 01-DEC-1988    CNK <tex@cran.rmcs>
  10.     Increase max_toks to 55000
  11. 12-DEC-1988     BHK <tex@cran.rmcs>
  12.     Emit VMS exit status
  13. 14-AUG-1989    Alien@ESSEX.ESE
  14.     Modify for tangle 2.9.
  15.     Default extension for pool file now .POOL
  16. 29-AUG-1989    BHK <tex@cran.rmcs>
  17.     Increase max_names to 5000
  18. 28-SEP-1989    BHK <tex@cran.rmcs>
  19.     Modify for tangle 3
  20. 03-NOV-1989    BHK <tex@cran.rmcs>
  21.     Modify for tangle 4 (eight-bit ASCII, etc)
  22. 24-SEP-1990    BHK <tex@cran.rmcs>
  23.     Modify for tangle v4.1
  24.  
  25. @x
  26. \pageno=\contentspagenumber \advance\pageno by 1
  27. @y
  28. \pageno=\contentspagenumber \advance\pageno by 1
  29. \let\maybe=\iffalse
  30. \def\title{TANGLE changes for Vax/VMS}
  31. @z
  32.  
  33. @x  <<<<<Modified 04-NOV-1989 by BHK <tex@uk.ac.cran.rmcs> for V4>>>>>
  34. @d banner=='This is TANGLE, Version 4.1'
  35. @y
  36. @d banner=='This is TANGLE, Vax/VMS Version 4.1'
  37. @z
  38.  
  39. @x
  40. and the string pool output goes to file |pool|.
  41. @y
  42. and the string pool output goes to file |pool|.
  43. VMS requires us to mention |input| and |output| in the program header, too.
  44. They are used for terminal input and output.
  45. @z
  46.  
  47. @x
  48. program TANGLE(@!web_file,@!change_file,@!Pascal_file,@!pool);
  49. @y
  50. program TANGLE(@!input,@!output,@!web_file,@!change_file,@!Pascal_file,
  51.     @!pool);
  52. @z
  53.  
  54. @x
  55. @<Compiler directives@>=
  56. @{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead}
  57. @!debug @{@&$C+,D+@}@+ gubed {but turn everything on when debugging}
  58. @y
  59. On Vax/VMS, things are a bit different.
  60.  
  61. @<Compiler directives@>=
  62. @=[check(none),inherit('sys$library:starlet')]@> {no debug overhead, but...}
  63. debug @=[check(all),inherit('sys$library:starlet')]@> gubed {turn everything on when debugging}
  64. @z
  65.  
  66. @x
  67. @d othercases == others: {default for cases not listed explicitly}
  68. @y
  69. @d othercases == otherwise {Vax/VMS default for cases not listed
  70.  explicitly}
  71. @z
  72.  
  73. @x <<<<< Added 01-DEC-1988 by CNK, modified 29-AUG-1989 by BHK <tex@cran.rmcs> >>>>>
  74. @!max_toks=50000; {|1/zz| times the number of bytes in compressed \PASCAL\ code;
  75.   must be less than 65536}
  76. @!max_names=4000; {number of identifiers, strings, module names;
  77.   must be less than 10240}
  78. @y
  79. @!max_toks=55000; {|1/zz| times the number of bytes in compressed \PASCAL\ code;
  80.   must be less than 65536}
  81. @!max_names=5000; {number of identifiers, strings, module names;
  82.   must be less than 10240}
  83. @z
  84.  
  85. @x
  86. @!text_file=packed file of text_char;
  87. @y
  88. @!text_file=text;
  89. @z
  90.  
  91. @x
  92. @d print_ln(#)==write_ln(term_out,#) {`|print|' and then start new line}
  93. @d new_line==write_ln(term_out) {start new line}
  94. @y
  95. @d print_ln(#)==write_ln(term_out,#,chr(13),chr(10))
  96.     {`|print|' and then start new line}
  97. @d new_line==write_ln(term_out,chr(13),chr(10)) {start new line}
  98. @z
  99.  
  100. @x
  101. rewrite(term_out,'TTY:'); {send |term_out| output to the terminal}
  102. @y
  103. open(term_out,'SYS$OUTPUT',@=carriage_control:=none@>);
  104. rewrite(term_out);
  105. @z
  106.  
  107. @x
  108. @d update_terminal == break(term_out) {empty the terminal output buffer}
  109. @y
  110. @d update_terminal == write_ln(term_out) {empty the terminal output buffer}
  111. @z
  112.  
  113. @x
  114. @ The following code opens |Pascal_file| and |pool|.
  115. Since these files were listed in the program header, we assume that the
  116. \PASCAL\ runtime system has checked that suitable external file names have
  117. been given.
  118. @^system dependencies@>
  119.  
  120. @<Set init...@>=
  121. rewrite(Pascal_file); rewrite(pool);
  122. @y
  123. @ The following code opens |Pascal_file| and |pool|.
  124. Acutally, on Vax/VMS this task is put off until later.
  125. @^system dependencies@>
  126. @z
  127.  
  128. @x
  129. @ Input goes into an array called |buffer|.
  130.  
  131. @<Globals...@>=@!buffer: array[0..buf_size] of ASCII_code;
  132. @y
  133. @ Input goes into an array called |buffer|.
  134. Actually, it is first read into |temp_buffer|.
  135. @<Glob...@>=
  136. @!buffer: array[0..buf_size] of ASCII_code;
  137. @!temp_buffer: varying [buf_size] of char;
  138. @z
  139.  
  140. @x
  141. @p function input_ln(var f:text_file):boolean;
  142.   {inputs a line or returns |false|}
  143. var final_limit:0..buf_size; {|limit| without trailing blanks}
  144. begin limit:=0; final_limit:=0;
  145. if eof(f) then input_ln:=false
  146. else  begin while not eoln(f) do
  147.     begin buffer[limit]:=xord[f^]; get(f);
  148.     incr(limit);
  149.     if buffer[limit-1]<>" " then final_limit:=limit;
  150.     if limit=buf_size then
  151.       begin while not eoln(f) do get(f);
  152.       decr(limit); {keep |buffer[buf_size]| empty}
  153.       if final_limit>limit then final_limit:=limit;
  154.       print_nl('! Input line too long'); loc:=0; error;
  155. @.Input line too long@>
  156.       end;
  157.     end;
  158.   read_ln(f); limit:=final_limit; input_ln:=true;
  159.   end;
  160. end;
  161. @y
  162. On Vax/VMS we first read a line into |temp_buffer|, since that's faster.
  163.  
  164. @p function input_ln(var f:text_file):boolean;
  165.   {inputs a line or returns |false|}
  166. var i,@!l:0..buf_size;
  167. begin limit:=0;
  168. if eof(f) then input_ln:=false
  169. else  begin
  170.     read(f,temp_buffer);
  171.     l:=temp_buffer.@=length@>;
  172.     for i:=1 to l do begin
  173.         buffer[i-1]:=xord[temp_buffer[i]];
  174.         if buffer[i-1]<>" " then limit:=i;
  175.         end;
  176.     if not eoln(f) then begin
  177.         print_nl('! Input line too long'); error;
  178. @.Input line too long@>
  179.         end
  180.     else read_ln(f);
  181.     input_ln:=true;
  182.     end;
  183. end;
  184. @z
  185.  
  186. @x
  187. @d ww=2 {we multiply the byte capacity by approximately this amount}
  188. @y
  189. @d ww=3 {we multiply the byte capacity by approximately this amount}
  190. @z
  191.  
  192. @x
  193. for k:=1 to break_ptr do write(Pascal_file,xchr[out_buf[k-1]]);
  194. write_ln(Pascal_file); incr(line);
  195. @y
  196. for k:=1 to break_ptr do out_temp_buffer[k]:=xchr[out_buf[k-1]];
  197. write_ln(Pascal_file,substr(out_temp_buffer,1,break_ptr)); incr(line);
  198. @z
  199.  
  200. @x
  201. @!term_in:text_file; {the user's terminal as an input file}
  202. @y
  203. @z
  204.  
  205. @x
  206. @<Set init...@>=
  207. @y
  208. @d term_in==input
  209.  
  210. @<Set init...@>=
  211. @z
  212.  
  213. @x
  214. reset(term_in,'TTY:','/I'); {open |term_in| as the terminal, don't do a |get|}
  215. @y
  216. @z
  217.  
  218. @x save pool and Pascal files only if they were written to.
  219. if string_ptr>256 then @<Finish off the string pool file@>;
  220. stat @<Print statistics about memory usage@>;@+tats@;@/
  221. @t\4\4@>{here files should be closed if the operating system requires it}
  222. @y
  223. if history<fatal_message then begin
  224.     if string_ptr>256 then begin @<Finish off the string pool file@>;
  225.         close(pool,@=disposition:=save@>,@=error:=continue@>);
  226.         end;
  227.     close(Pascal_file,@=disposition:=save@>,@=error:=continue@>);
  228.     end;
  229. stat @<Print statistics about memory usage@>;@+tats@;@/
  230. @z
  231.  
  232.  
  233. @x <<<<< Added 12-DEC-1988 by BHK <tex@cran.rmcs> >>>>>
  234. @ Some implementations may wish to pass the |history| value to the
  235. operating system so that it can be used to govern whether or not other
  236. programs are started. Here we simply report the history to the user.
  237. @^system dependencies@>
  238.  
  239. @<Print the job |history|@>=
  240. case history of
  241. spotless: print_nl('(No errors were found.)');
  242. harmless_message: print_nl('(Did you see the warning message above?)');
  243. error_message: print_nl('(Pardon me, but I think I spotted something wrong.)');
  244. fatal_message: print_nl('(That was a fatal error, my friend.)');
  245. end {there are no other cases}
  246. @y
  247. @ This implementation passes the |history| value to the
  248. operating system so that it can be used to govern whether or not other
  249. programs are started; we also report the history to the user here.
  250. @^system dependencies@>
  251.  
  252. @d VAX_exit==@=$exit@>
  253. @d VAX_ss_normal==@= sts$k_success @>
  254. @d VAX_ss_warning==@= sts$k_warning + sts$m_inhib_msg @>
  255. @d VAX_ss_error==@= sts$k_error + sts$m_inhib_msg @>
  256. @d VAX_ss_fatal==@= sts$k_severe + sts$m_inhib_msg @>
  257.  
  258. @<Print the job |history|@>=
  259. case history of
  260. spotless: begin print_nl('(No errors were found.)');
  261.    VAX_exit(VAX_ss_normal) end;    { Everything OK! }
  262. harmless_message: begin print_nl('(Did you see the warning message above?)');
  263.    VAX_exit(VAX_ss_warning) end;
  264. error_message: begin
  265.    print_nl('(Pardon me, but I think I spotted something wrong.)');
  266.    VAX_exit(VAX_ss_error) end;
  267. fatal_message: begin print_nl('(That was a fatal error, my friend.)');
  268.    VAX_exit(VAX_ss_fatal) end {there are no other cases}
  269. end;
  270. @z
  271.  
  272. @x
  273. This module should be replaced, if necessary, by changes to the program
  274. that are necessary to make \.{TANGLE} work at a particular installation.
  275. It is usually best to design your change file so that all changes to
  276. previous modules preserve the module numbering; then everybody's version
  277. will be consistent with the printed program. More extensive changes,
  278. which introduce new modules, can be inserted here; then only the index
  279. itself will get a new module number.
  280. @y
  281. Here are the remaining changes to the program
  282. that are necessary to make \.{TANGLE} work on Vax/VMS.
  283.  
  284.  
  285. @ This variable is for speeding up the output routine.
  286.  
  287. @<Glob...@>=
  288. @!out_temp_buffer:packed array [1..out_buf_size] of char;
  289.  
  290. @ On Vax/VMS we need the following special definitions, types, variables
  291. and procedures to be able to get the file name from the command line,
  292. or to prompt for them.  We also define here those symbols required to be
  293. able to emit status on exit.
  294.  
  295. @d VAX_volatile==@=volatile@>
  296. @d VAX_immed==@=%immed @>
  297. @d VAX_external==@=external@>
  298. @d VAX_stdescr==@=%stdescr @>
  299. @d VAX_lib_get_foreign==@= lib$get_foreign@>
  300. @d VAX_length==@=length @>
  301.  
  302. @ @<Local...@>=
  303. @!command_line:packed array[1..300] of char;
  304. @!cmd_len:sixteen_bits;
  305. @!cmd_i:integer;
  306. @!file_name,@!default_file_name:varying [300] of char;
  307. @!ask,@!got_file_name: boolean;
  308.  
  309. @ Here is the library procedure that gets the user's command line.
  310.  
  311. @<Error...@>=
  312. [VAX_external] function VAX_lib_get_foreign(
  313.   VAX_stdescr cmdlin:[VAX_volatile] packed array [$l1..$u1:integer] of char
  314.     := VAX_immed 0;
  315.   VAX_stdescr prompt:[VAX_volatile] packed array [$l2..$u2:integer] of char
  316.     := VAX_immed 0;
  317.   var len : [VAX_volatile] sixteen_bits := VAX_immed 0;
  318.   var flag : [VAX_volatile] integer := VAX_immed 0)
  319.     :integer; extern;
  320.  
  321. @ We get the external file names, and then call |open|
  322. to associate an external file with each file variable.
  323.  
  324. @<Set init...@>=
  325. cmd_i:=0;
  326. cmd_len := 0 ;
  327. VAX_lib_get_foreign(command_line,,cmd_len,cmd_i);
  328. cmd_i:=1; while (cmd_i<=cmd_len) and (command_line[cmd_i]=' ') do incr(cmd_i);
  329. got_file_name:=cmd_i<=cmd_len;
  330. if got_file_name then
  331.     default_file_name:=substr(command_line,cmd_i,cmd_len-cmd_i+1);
  332.  
  333. if got_file_name then begin
  334.     file_name:=default_file_name+'.WEB';
  335.     open(web_file,file_name,@=readonly@>,@=error:=continue@>);
  336.     ask:=status(web_file)<>0;
  337.     if ask then write_ln('Couldn''t open ',file_name);
  338.     end
  339. else ask:=true;
  340. while ask do begin
  341.     got_file_name:=false;
  342.     write('Web file: ');
  343.     if eof then begin mark_fatal; jump_out; end;
  344.     read_ln(file_name);
  345.     open(web_file,file_name,@=readonly@>,@=error:=continue@>);
  346.     ask:=status(web_file)<>0;
  347.     if ask then write_ln('Couldn''t open ',file_name);
  348.     end;
  349.  
  350. if got_file_name then begin
  351.     file_name:=default_file_name+'.CH';
  352.     open(change_file,file_name,@=readonly@>,@=error:=continue@>);
  353.     ask:=status(change_file)>0; {can be empty}
  354.     if ask then write_ln('Couldn''t open ',file_name);
  355.     end
  356. else ask:=true;
  357. while ask do begin
  358.     write('Change file: ');
  359.     if eof then begin mark_fatal; jump_out; end;
  360.     read_ln(file_name);
  361.     if file_name.VAX_length=0 then file_name:='NL:';
  362.     open(change_file,file_name,@=readonly@>,@=error:=continue@>);
  363.     ask:=status(change_file)>0;
  364.     if ask then write_ln('Couldn''t open ',file_name);
  365.     end;
  366.  
  367. if got_file_name then begin
  368.     cmd_i:=1;
  369.     for cmd_len:=1 to default_file_name.VAX_length do
  370.         if (default_file_name[cmd_len]=']')
  371.         or (default_file_name[cmd_len]=':')
  372.         then cmd_i:=cmd_len+1;
  373.     if cmd_i<=default_file_name.VAX_length then
  374.         default_file_name:=substr(default_file_name,cmd_i,
  375.             default_file_name.VAX_length-cmd_i+1);
  376.     end;
  377.  
  378. if got_file_name then begin
  379.     file_name:=default_file_name+'.PAS';
  380.     open(Pascal_file,file_name,@=new,disposition:=delete@>,
  381.         @=error:=continue@>);
  382.     ask:=status(Pascal_file)>0;
  383.     if ask then write_ln('Couldn''t open ',file_name);
  384.     end
  385. else ask:=true;
  386. while ask do begin
  387.     write('Pascal file: ');
  388.     if eof then begin mark_fatal; jump_out; end;
  389.     read_ln(file_name);
  390.     open(Pascal_file,file_name,@=new,disposition:=delete@>,
  391.         @=error:=continue@>);
  392.     ask:=status(Pascal_file)>0;
  393.     if ask then write_ln('Couldn''t open ',file_name);
  394.     end;
  395.  
  396. if got_file_name then begin
  397.     file_name:=default_file_name+'.POOL';
  398.     open(pool,file_name,@=new,disposition:=delete@>,@=error:=continue@>);
  399.     ask:=status(pool)>0;
  400.     if ask then write_ln('Couldn''t open ',file_name);
  401.     end
  402. else ask:=true;
  403. while ask do begin
  404.     write('Pool file: ');
  405.     if eof then begin mark_fatal; jump_out; end;
  406.     read_ln(file_name);
  407.     open(pool,file_name,@=new,disposition:=delete@>,@=error:=continue@>);
  408.     ask:=status(pool)>0;
  409.     if ask then write_ln('Couldn''t open ',file_name);
  410.     end;
  411.  
  412. rewrite(Pascal_file); rewrite(pool);
  413. @z
  414.